﻿using System;
using System.Diagnostics;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using MediaAssistant.DAL;
using MediaAssistant.DAL.Constants;

namespace MediaAssistant.Converters
{
    public class DoneStatusInverseVisibilityConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values[0] == DependencyProperty.UnsetValue)
                return Visibility.Visible;
            Debug.WriteLine("Waiting for lock at DoneStatusInverseVisibilityConverter");
            lock (DatabaseManager.LockObject)
            {
                Debug.WriteLine("lock at DoneStatusInverseVisibilityConverter");
                var movie = (Movie)values[0];
                var visibility = movie != null && movie.Status == MovieStatus.Done ? Visibility.Collapsed : Visibility.Visible;
                Debug.WriteLine("unlock at DoneStatusInverseVisibilityConverter");
                return visibility;    
            }
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}